<template>
  <div class="nav">
    <ul>
      <li v-for="(item) in navList" :key="item.id"
      :class="{active: isActive === item.id
      }" @click="isActive = item.id">{{ item.title }}</li>
    </ul>
  </div>
</template>

<script setup>
  import { ref } from 'vue';
  const isActive = ref(1)
  const navList = ref([
    {
      id:1,
      name:'首页'
    },
    {
      id:2,
      name:'社区'
    },
    {
      id:3,
      name:'我的'
    }
  ])
</script>

<style scoped>
  * {
    margin: 0;
    padding: 0;
    list-style: none;
  }

  ul {
    display: flex;
  }
  ul li {
    display: block;
    padding: 20px;
    border: 1px solid black;
    margin: 20px;
    background-color: aqua;
  }

  .active {
    background-color: red;
  }
</style>